package com.example.pilipili.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.pilipili.common.R;
import com.example.pilipili.pojo.entity.Like;
import com.example.pilipili.service.LikeService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.time.LocalDate;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liyv
 * @since 2023-12-01
 */
@RestController
@RequestMapping("/likes")
public class LikeController {

    @Autowired
    LikeService likeService ;

    /**
     * 点击点赞按钮
     * @param like uid,vid
     * @return
     */
    @PostMapping
    public R<Like> addLike(@RequestBody @Valid Like like){
        return likeService.click(like) ;
    }

    /**
     * 某用户对某视频 是否收藏
     * @param like uid ， vid
     * @return boolean
     */
    @PostMapping("/init")
    public R getInitForU(@RequestBody @Valid Like like){
        return R.ok(likeService.isLiked(like.getUid(),like.getVid())) ;
    }

    /**
     * 我的作品点赞数
     * @param uid uid
     * @return int
     */
    @GetMapping("/likeme/{uid}")
    public R likeMe(@PathVariable int uid){
        return likeService.UserLikesNum(uid) ;
    }


}

